﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;

namespace FrameworkEditor
{
    internal class OneToOneCopy : IAbSetting
    {
        internal OneToOneCopy(string path, string regex) : base(path, regex)
        {

        }
        internal override List<AssetBundleBuild> GetAllBuilders()
        {
            List<AssetBundleBuild> ret = new List<AssetBundleBuild>();
            if (string.IsNullOrEmpty(DirPath))
            {
                return ret;
            }

            if (!Directory.Exists(DirPath))
            {
                Debug.LogWarning("OneToOneCopy DirPath = " + DirPath + " does not exists!");
                return ret;
            }

            foreach (string file in Directory.GetFiles(DirPath, "*.*", SearchOption.AllDirectories))
            {
                if (!IsNeedBuild(file))
                {
                    continue;
                }

                string assetPath = EditorUtils.GetPathRelativeToAssets(file);
                string abName = EditorUtils.GetRelativePathToDir(assetPath, EditorUtils.assetRootDir);
                //Debug.Log("OneToOneCopy abName = " + abName + " assetPath = " + assetPath);
                ret.Add(new AssetBundleBuild()
                {
                    assetBundleName = abName,
                    assetNames = new string[] { assetPath },
                });
            }
            return ret;
        }
    }
}
